package cn.edu.hqu.cst.android.xzy.NO2;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    TextView t0,t1,t2,t3,t4,t5,t6,t7,t8;

    public void setT0() {
        this.t0.setText("外部类");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        t0=findViewById(R.id.tv0);
        t1=findViewById(R.id.tv1);
        t2=findViewById(R.id.tv2);
        t3=findViewById(R.id.tv3);
        t4=findViewById(R.id.tv4);
        t5=findViewById(R.id.tv5);
        t6=findViewById(R.id.tv6);
        t7=findViewById(R.id.tv7);
        t8=findViewById(R.id.tv8);

        t1.setOnClickListener(this);
        t2.setOnClickListener(new MainActivity.MyClickListener());

        t3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                t0.setText("匿名内部类");
            }
        });

        t4.setOnClickListener(t4->{
            t0.setText("Lambda表达式");
        });

        t5.setOnClickListener(new myOnClickListener(){
            @Override
            public void onClick(View v) {
                setT0();
            }
        });

        t7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转页面
                Intent intent5 = new Intent(MainActivity.this,SystemInfoActivity.class);
                startActivity(intent5);
            }
        });

        t8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转页面
                Intent intent5 = new Intent(MainActivity.this,ProgressDialogTest.class);
                startActivity(intent5);
            }
        });


    }

    @Override
    public void onClick(View v) {
        t0.setText("Activity作为监听器");
    }
    //定义一个单击事件的监听器
    class MyClickListener implements View.OnClickListener{
        @Override
        public void onClick(View v){
            t0.setText("由内部类监听!");
        }
    }
    public void mynewonClick(View v){
        t0.setText("监听器绑定到标签");
    }
}

class myOnClickListener implements View.OnClickListener{
    @Override
    public void onClick(View v) {
        MainActivity m1 = new MainActivity();
        m1.setT0();
    }
}